﻿using System.Collections.Generic;
using System.Data;
using Smarly.Bussines.Membership;
using Smarly.Core;
using Smarly.Core.Database;

namespace Smarly.Bussines.Model.Account
{
	public class Editor : ModelStateObject
	{
		public string HashTag { get; set; }
		public bool Allow { get; protected set; }

		internal Editor AllowEdit(SmarlyIdentity user)
		{
			return SqlRepository.ExecuteProcedureReader("User_Roles_AllowEdit",
																					 new List<SpParam>
			                                     	{
			                                     		new SpParam {Name = "@userId", Type = DbType.Guid, Value = user.UserId},
			                                     		new SpParam {Name = "@hashTag", Type = DbType.String, Value = HashTag},
			                                     	},
																					 OnSqlInfoMessage,
																					 reader =>
																					 {
																						 while (reader.Read())
																						 {
																							 Allow = reader.GetBoolean("AllowEdit");
																						 }
																						 return this;
																					 });
		}
	}
}